﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class carMoving : MonoBehaviour
{
	// Start is called before the first frame update
	public float movingSpeed;
	public Transform posBegin;
	public Transform posEnd;
	void Start()
	{

	}

	// Update is called once per frame
	void Update()
	{

	}

	private void FixedUpdate()
	{
		transform.position += Vector3.right * movingSpeed * Time.deltaTime;
		if (posBegin != null)
			if ((transform.position - posEnd.position).magnitude < 2)
			{
				transform.position = posBegin.position;
			}
		
	}
	private void OnTriggerEnter(Collider other)
	{
		transform.position -= new Vector3(500, 0, 0);

	}
}
